import defaultValue from './defaultValue'
// import { timejlMinfn, daystrfn } from '@/utils/base'
import store from '@/store'
import test from '@/utils/test'
import deepClone from '@/z/callback/deepClone'
const ChargeCarsearchjson = [
  {
    label: '桩号',
    value: 'gtel',
  },
  {
    label: '桩名',
    value: 'mc',
  },
  {
    label: '设备状态',
    value: 'gzt',
    type: 'select',
    option: [{ label: '全部', value: '' }, ...defaultValue.gzt],
  },
  {
    label: '所属站点',
    value: 'pcs',
    type: 'pcs',
  },
  {
    label: '设备类型',
    value: 'gtype',
    type: 'select',
    option: [{ label: '全部', value: '' }, ...defaultValue.gtype],
  },
]
// 桩号	桩名	添加时间	状态	使用率	设备型号	收费模式
// {
//   /* <td>{{p.gtel}}</td>
//             <td>{{p.mc}}</td>
//             <td>{{p.sjc}}</td>
//             <td>{{selectxsfn(p.gzt,"gzt")}}</td>
//             <td>{{p.syl}}%</td>

//             <td>{{selectxsfn(p.xtype,"xtype")}}</td>
//             <!--            <td>{{selectxsfn(p,"sjzx")}}</td>-->
//             <td>{{selectxsfn(p.type,"type")}}</td> */
// }
const ChargeCartablejson = [
  {
    label: '桩号',
    value: 'gtel',
  },
  {
    label: '桩名',
    value: 'mc',
  },
  {
    label: '添加时间',
    value: 'sjc',
  },
  {
    label: '状态',
    value: 'gzt',
    type: 'select',
    option: [...defaultValue.gzt],
  },
  {
    label: '使用率',
    value: 'syl',
    dw: '%',
  },

  {
    label: '设备型号',
    value: 'xtype',
    type: 'select',
    option: [
      { label: '未知', value: '0' },
      { label: '10路充电桩', value: '1' },
      { label: '5路充电桩', value: '2' },
      { label: '20路充电桩', value: '5' },
      { label: '不定路数充电桩', value: '3' },
      { label: '四合一充电桩', value: '4' },
      { label: '2路大功率设备', value: '6' },
      { label: '户外四路箱式', value: '7' },
    ],
  },

  {
    label: '收费模式',
    value: 'type',
    type: 'select',
    option: [...defaultValue.type],
  },
]
const ChargeCartypejson = [
  {
    label: '电费单价',
    value: 'df',
    dw: '元/度',
    defaultValue: '1',
    fl: 100,
    if: {
      zhi: [{ value: 'type', zhi: ['1', '10', '11'] }],
    },
    rule: [
      {
        required: true,
        message: '电费单价错误',
        trigger: 'change',
        validator(rule, value, callback) {
          if (!test.amount(value)) {
            callback(new Error('error'))
          } else {
            callback()
          }
        },
      },
    ],
    // validator
  },
  {
    label: '刷卡时长',
    value: 'jebd',
    dw: '小时',
    defaultValue: '1',
    if: {
      zhi: [{ value: 'type', zhi: ['5', '6', '7'] }],
    },
  },
  {
    label: '费用',
    value: 'df',
    dw: '元/时',
    defaultValue: '0.3',
    fl: 100,
    if: {
      zhi: [{ value: 'type', zhi: ['5', '7'] }],
    },
    rule: [
      {
        required: true,
        message: '费用错误',
        trigger: 'change',
        validator(rule, value, callback) {
          if (!test.amount(value)) {
            callback(new Error('error'))
          } else {
            callback()
          }
        },
      },
    ],
  },
  {
    label: '充电时长',
    value: 'df',
    dw: '分钟/1元',
    defaultValue: '240',

    if: {
      zhi: [{ value: 'type', zhi: ['2', '4', '13'] }],
    },

    rule: [
      {
        required: true,
        message: '充电时长错误',
        trigger: 'change',
        validator(rule, value, callback) {
          if (!test.digits(value)) {
            callback(new Error('error'))
          } else {
            callback()
          }
        },
      },
    ],
  },
  {
    label: '基础功率',
    value: 'dfsj',
    dw: '瓦',
    defaultValue: '220',

    if: {
      zhi: [{ value: 'type', zhi: ['13'] }],
    },
  },
  {
    label: '刷卡时长',
    value: 'jebd',
    dw: '分钟/1元',
    defaultValue: '240',
    if: {
      zhi: [{ value: 'type', zhi: ['2'] }],
    },

    rule: [
      {
        required: true,
        message: '刷卡时长错误',
        trigger: 'change',
        validator(rule, value, callback) {
          if (!test.digits(value)) {
            callback(new Error('error'))
          } else {
            callback()
          }
        },
      },
    ],
  },
  {
    label: '最低费用',
    value: 'qbf',
    dw: '元',
    defaultValue: '1',
    fl: '100',
    if: {
      zhi: [{ value: 'type', zhi: ['2', '3', '8'] }],
    },
    rule: [
      {
        required: true,
        message: '最低费用错误',
        trigger: 'change',
        validator(rule, value, callback) {
          if (!test.amount(value)) {
            callback(new Error('error'))
          } else {
            callback()
          }
        },
      },
    ],
  },
  {
    label: '服务费',
    value: 'qbf',
    dw: '元',
    defaultValue: '1',
    fl: '100',
    if: {
      zhi: [{ value: 'type', zhi: ['10'] }],
    },
    rule: [
      {
        required: true,
        message: '服务费错误',
        trigger: 'change',
        validator(rule, value, callback) {
          if (!test.amount(value)) {
            callback(new Error('error'))
          } else {
            callback()
          }
        },
      },
    ],
  },
  {
    label: '时间设置',
    value: 'dfsj',
    dw: '分',
    defaultValue: '60',
    if: {
      zhi: [{ value: 'type', zhi: ['10'] }],
    },
  },
  {
    label: '1档瓦数',
    value: 'a1',
    dw: 'w',
    defaultValue: '200',
    if: {
      zhi: [{ value: 'type', zhi: ['3', '8', '6'] }],
    },
    type: 'typew',
  },
  {
    label: '1档时长',
    value: 'df1',
    dw: '元/时',
    defaultValue: '0.3',
    fl: '100',
    if: {
      zhi: [{ value: 'type', zhi: ['6'] }],
    },
  },
  {
    label: '1档充电时长',
    value: 'df1',
    dw: '分钟/1元',
    defaultValue: '240',
    if: {
      zhi: [{ value: 'type', zhi: ['3', '8'] }],
    },
  },
  {
    label: '2档瓦数',
    value: 'a2',
    dw: 'w',
    defaultValue: '350',
    if: {
      zhi: [{ value: 'type', zhi: ['3', '8', '6'] }],
    },
    type: 'typew',
    prevalue: 'a1',
  },
  {
    label: '2档充电时长',
    value: 'df2',
    dw: '分钟/1元',
    defaultValue: '180',
    if: {
      zhi: [{ value: 'type', zhi: ['3', '8'] }],
    },
  },
  {
    label: '2档时长',
    value: 'df2',
    dw: '元/时',
    defaultValue: '0.4',
    fl: '100',
    if: {
      zhi: [{ value: 'type', zhi: ['6'] }],
    },
  },
  {
    label: '3档瓦数',
    value: 'a3',
    dw: 'w',
    defaultValue: '600',
    if: {
      zhi: [{ value: 'type', zhi: ['3', '8', '6'] }],
    },
    type: 'typew',
    prevalue: 'a2',
  },
  {
    label: '3档充电时长',
    value: 'df3',
    dw: '分钟/1元',
    defaultValue: '120',
    if: {
      zhi: [{ value: 'type', zhi: ['3', '8'] }],
    },
  },
  {
    label: '3档时长',
    value: 'df3',
    dw: '元/时',
    defaultValue: '0.5',
    fl: '100',
    if: {
      zhi: [{ value: 'type', zhi: ['6'] }],
    },
  },
  {
    label: '4档瓦数',
    value: 'a4',
    dw: 'w',
    defaultValue: '900',
    if: {
      zhi: [{ value: 'type', zhi: ['3', '8', '6'] }],
    },
    type: 'typew',
    prevalue: 'a3',
  },
  {
    label: '4档充电时长',
    value: 'df4',
    dw: '分钟/1元',
    defaultValue: '60',
    if: {
      zhi: [{ value: 'type', zhi: ['3', '8'] }],
    },
  },
  {
    label: '4档时长',
    value: 'df4',
    dw: '元/时',
    defaultValue: '0.6',
    fl: '100',
    if: {
      zhi: [{ value: 'type', zhi: ['6'] }],
    },
  },
  {
    label: '超时费用',
    value: 'dfsj',
    dw: '元/时',
    defaultValue: '0.5',
    fl: '100',

    if: {
      zhi: [{ value: 'type', zhi: ['4'] }],
    },
  },
  {
    label: '退款时间',
    value: 'dfsj',
    defaultValue: '60',
    if: {
      zhi: [{ value: 'type', zhi: ['7', '8'] }],
    },
    dw: '分',
  },
  {
    label: '保底金额',
    value: 'jebd',
    defaultValue: '0',
    fl: '100',
    if: {
      zhi: [{ value: 'type', zhi: ['8'] }],
    },
    dw: '元',
  },
  {
    label: '租置费用',
    value: 'df1',
    defaultValue: '180',
    fl: '100',
    if: {
      zhi: [{ value: 'type', zhi: ['11'] }],
    },
    dw: '元/小时',
  },

  {
    label: '1档费用',
    value: 'a1',
    defaultValue: '1',
    if: {
      zhi: [{ value: 'type', zhi: ['9'] }],
    },
    fl: '100',
    dw: '元',
    span: 7,
  },
  {
    label: '/',
    value: 'df1',
    defaultValue: '180',
    if: {
      zhi: [{ value: 'type', zhi: ['9'] }],
    },
    dw: '分钟',
    span: 5,
    labelwidth: 'auto',
  },
  {
    label: '2档费用',
    value: 'a2',
    defaultValue: '2',
    if: {
      zhi: [{ value: 'type', zhi: ['9'] }],
    },
    fl: '100',
    dw: '元',
    span: 7,
  },
  {
    label: '/',
    value: 'df2',
    defaultValue: '480',
    if: {
      zhi: [{ value: 'type', zhi: ['9'] }],
    },
    dw: '分钟',
    span: 5,
    labelwidth: 'auto',
  },
  {
    label: '3档费用',
    value: 'a3',
    defaultValue: '0',
    if: {
      zhi: [{ value: 'type', zhi: ['9'] }],
    },
    fl: '100',
    dw: '元',
    span: 7,
  },
  {
    label: '/',
    value: 'df3',
    defaultValue: '0',
    if: {
      zhi: [{ value: 'type', zhi: ['9'] }],
    },
    dw: '分钟',
    span: 5,
    labelwidth: 'auto',
  },
  {
    label: '4档费用',
    value: 'a4',
    defaultValue: '0',
    if: {
      zhi: [{ value: 'type', zhi: ['9'] }],
    },
    fl: '100',
    dw: '元',
    span: 7,
  },
  {
    label: '/',
    value: 'df4',
    defaultValue: '0',
    if: {
      zhi: [{ value: 'type', zhi: ['9'] }],
    },
    dw: '分钟',
    span: 5,
    labelwidth: 'auto',
  },
]
const ChargeCaraddjson = [
  {
    label: '桩号',
    value: 'gtel',
    rule: [
      {
        required: true,
        message: '请输入桩号',
        trigger: 'blur',
      },
    ],
  },
  {
    label: '桩名',
    value: 'mc',
  },
  {
    label: '地址',
    value: 'dz',
    type: 'mpt',
    mptvalue: 'wz',
  },
  {
    label: '所属站点',
    value: 'pcs',
    type: 'pcs',
    defaultValue: store.getters['user/token'].pcs,
    defaultText: '请选择',
    rule: [{ required: true, message: '请选择所属站点', trigger: 'blur' }],
  },
  {
    label: '收费模式',
    value: 'type',
    type: 'select',
    if: {
      zhierror: [{ value: 'gtype', zhi: ['2', '10', '61', '62'] }],
    },
    option: [...defaultValue.type],
    defaultValue: '2',
  },
  {
    label: '收费模式',
    value: 'type',
    type: 'select',
    if: {
      zhi: [{ value: 'gtype', zhi: ['2', '10'] }],
    },
    option: [
      ...defaultValue.type.filter((e) => {
        return ['0', '1', '2'].find((f) => {
          return f == e.value
        })
      }),
    ],
    defaultValue: '1',
  },
  {
    label: '收费模式',
    value: 'type',
    type: 'select',
    if: {
      zhi: [{ value: 'gtype', zhi: ['61', '62'] }],
    },
    option: [
      ...defaultValue.type.filter((e) => {
        return ['1'].find((f) => {
          return f == e.value
        })
      }),
    ],
    defaultValue: '1',
  },
  ...ChargeCartypejson,
  {
    label: '备注',
    value: 'bz',
  },
  {
    value: 'jedbdf',
    label: '电费金额',
    fl: '100',
    dw: '元',
    if: {
      zhierror: [{ value: 'type', zhi: ['12', '13'] }],
    },
  },
  {
    label: '照片',
    value: 'zp',
    type: 'img',
  },
]
const ChargeCaredtjson = [
  {
    label: '联系人',
    value: 'uxm',
    type: 'button',
    valuecallbackasync: async (data) => {
      let z = await store.dispatch('usearch/getusearchone', data.uUser)

      return z.uxm ? z.uxm : ''
    },
  },
  {
    label: '联系电话',
    value: 'utel',
    type: 'button',
    // valuecallbackasync: async (data) => {
    //   let z = await store.dispatch('usearch/getusearchone', data.uUser)
    //   return z.utel ? z.utel : ''
    // },
  },
  ...deepClone(ChargeCaraddjson).map((e) => {
    if (e.value == 'gtel') {
      e.type = 'button'
    }
    if (e.value == 'type') {
      //
      e.callbackasync = async (data) => {
        if (data.gtel) {
          let ChargeCfg = await store.dispatch('request/getRequest', {
            url: '/ChargeCfg',
            data: { gtel: data.gtel },
          })
          ChargeCfg = ChargeCfg.length == 1 ? ChargeCfg[0] : {}
          if (
            !e.option.find(function (e) {
              return e.value == 13
            }) &&
            ChargeCfg.b_xxgl == 1
          ) {
            e.option.push({ label: '线性计费', value: '13' })
          }
        }

        return { ...e }
      }
    }
    return e
  }),
]
const defaultdatavalue = {
  a1: '0',
  df1: '0',
  a2: '0',
  df2: '0',
  a3: '0',
  df3: '0',
  a4: '0',
  df4: '0',
  df: '0',
  qbf: '0',
  dfsj: '0',
  jebd: '0',
  jedbdf: '0',
}

const exceldata = [
  { value: 'gtel', label: '桩号' },
  { value: 'mc', label: '桩名' },
  // { value: 'gsim', label: '物联网卡号' },
  { value: 'syl', label: '使用率', dw: '%', defaultValue: '0' },
  { value: 'dz', label: '地址' },
  { value: 'uxm', label: '联系人' },
  { value: 'utel', label: '联系电话' },
  {
    value: 'pcs',
    label: '所属站点',
    callbackasync: async (data) => {
      let r = await store.dispatch('station/getstationone', data.pcs)
      r = r.length == 0 ? '' : r[0].pcs
      return r
    },
  },
  { value: 'gls', label: '插座数量', dw: '路' },
  { value: 'sjc', label: '上线日期' },
  {
    value: 'bbh',
    label: '版本号',
    callback: (data) => {
      return `硬件版本:${data.yjbb} 软件版本:${data.rjbb};`
    },
  },
  {
    value: 'type',
    label: '收费模式',
    type: 'select',
    option: [...defaultValue.type],
  },
  { value: 'gxh', label: '信号强度', defaultValue: '0' },
  { value: 'sjup', label: '更新时间' },
]
const addsjson = [
  {
    label: '所属站点',
    value: 'pcs',
    type: 'pcs',
    defaultValue: store.getters['user/token'].pcs,
    defaultText: '请选择',
    rule: [{ required: true, message: '请选择所属站点', trigger: 'blur' }],
    span: 24,
  },
  {
    label: '选择Exel',
    value: 'excel',
    type: 'excel',
    defaultValue: '',
    span: 24,
    rule: [{ required: true, message: '请选择Exel', trigger: 'blur' }],
  },
]
let ChargeCfglx51 = [
  { label: '断电检测时间', value: 'ddjcc', dw: '秒' },
  { label: '投币充电时间', value: 'tbsj', dw: '分钟' },
  { label: '涓流时间', value: 'fcsj', dw: '分钟' },
  { label: '涓流功率值', value: 'jldl', dw: '瓦' },
  { label: '断开功率值', value: 'dkdl', dw: '瓦' },
  { label: '最大功率值', value: 'maxdl', dw: '瓦' },
  { label: '设备音量', value: 'b_yy', dw: '瓦' },
  { label: '全通卡卡号', value: 'cardid' },
  { label: '设备报警温度', value: 'wdsbal' },
  { label: '线缆报警温度', value: 'wdxlal' },
  { label: '流量卡信息', value: 'sim' },
  {
    label: '第二服务器IP',
    value: 'ip',
    if: { zhi: [{ value: 'b_dr', zhi: ['1'] }] },
  },
  {
    label: '第二服务器端口',
    value: 'port',
    if: { zhi: [{ value: 'b_dr', zhi: ['1'] }] },
  },
  { label: '打开投币箱', value: 'b_tb', type: 'switch' },
  { label: '插拔断电', value: 'b_cbdd', type: 'switch' },
  { label: '充满自停', value: 'b_dd', type: 'switch' },
  { label: '烟雾报警', value: 'b_al', type: 'switch' },
  { label: '第二服务器', value: 'b_dr', type: 'switch' },
]
let ChargeCfglx65 = [
  {
    callback: (data) => {
      let r = []
      for (var i = 1; i <= data.gls; i++) {
        r.push({ label: `${i}路设备温度`, value: `wddl${i}`, dw: '℃' })
      }
      return r
    },
  },
]
let states = [
  { label: '桩号', value: 'gtel', disabled: true },
  {
    label: '设备状态',
    value: 'gzt',
    type: 'select',
    option: [...defaultValue.gzt],
    disabled: true,
  },
]
let state1 = [
  {
    label: '信号强度',
    value: 'gxhxs',
    valuecallback: (data) => {
      let r = ''
      r =
        data.gxh == 0 || !data.gxh
          ? '无'
          : data.gxh < 20
          ? `弱${data.gxh}`
          : data.gxh <= 25
          ? `中${data.gxh}`
          : `强${data.gxh}`

      return r
    },
  },
  {
    callback: (data) => {
      let r = [
        {
          label: data.gzt == 0 ? '离线时间' : '更新时间',
          value: 'sjup',
          disabled: true,
          if: {
            zhierror: [{ value: 'gtype', zhi: ['61', '62'] }],
          },
        },
      ]
      return r
    },
  },
  {
    label: '烟感状态',
    value: 'gyg',
    type: 'select',
    option: [...defaultValue.gyg],
  },
  {
    label: '设备温度',
    value: 'gwd',
    dw: '℃',
    fl: '10',
  },
  {
    label: '抄表电量',
    value: 'dbdf',
    dw: 'A',
  },
  {
    label: '硬币收入',
    value: 'tbsum',
  },
]

let state2 = [
  {
    label: 'A表电量',
    value: 'gcdl1',
    dw: 'A',
  },
  {
    label: 'B表电量',
    value: 'gcdl2',
    dw: 'A',
  },
]
//
let state3 = [
  { label: '剩余电流', value: '剩余电流', defaultValue: '0' },
  { label: '故障电弧', value: '故障电弧', defaultValue: '无' },
  { label: '相电流', value: '相电流', defaultValue: '0' },
  { label: '脱钩联动', value: '脱钩联动', defaultValue: '无' },
  { label: '故障联动', value: '故障联动', defaultValue: '无' },
  { label: '报警联动', value: '报警联动', defaultValue: '无' },
  { label: '联动输入报警', value: '联动输入报警', defaultValue: '无' },
]
let state4 = [
  {
    callback: (data) => {
      let r = []
      let disabledfalg = true
      if (
        [4, 3, 15].find((e) => {
          return store.state.user.token.utype == e
        }) &&
        ![61, 62].find((e) => {
          return data.gtype == e
        })
      ) {
        disabledfalg = false
      }
      // if (($scope.USearch.utype == 4 || $scope.USearch.utype == 15 || $scope.USearch.utype == 3) && dqclickdata.gtype != 61&& dqclickdata.gtype != 62) {
      for (var i = 1; i <= data['gls']; i++) {
        r.push({
          label: `第${i}路`,
          value: `glzt${i}`,
          type: 'select',
          option: [...defaultValue.glzt],
          disabled: disabledfalg,
          typeurl: '/ChargeCarSysedt',
          typevalue: `glzt${i}`,
          upvalue: `gzt`,
          uodata: { td: i },
        })
      }
      if (
        [4, 3].find((e) => {
          return store.state.user.token.utype == e
        })
      ) {
        r.push({
          label: '设备配置',
          value: 'b_use',
          type: 'select',
          option: [...defaultValue.b_use],
          typeurl: '/ChargeCarQR',
          typevalue: 'b_use',
          upvalue: `b_use`,
        })
      }
      return r
    },
  },
]

states = states
  .concat(
    state1.map((e) => {
      e.disabled = true
      e.if = {
        zhierror: [{ value: 'gtype', zhi: ['61', '62'] }],
      }
      return e
    })
  )
  .concat(
    state2.map((e) => {
      e.disabled = true
      e.if = {
        zhi: [{ value: 'gtype', zhi: ['61', '62'] }],
      }
      return e
    })
  )
  .concat(
    state3
      .filter(() => {
        return store.getters['upw/b_info']
      })
      .map((e) => {
        e.disabled = true
        e.if = {
          zhi: [{ value: 'UPW_b_info', zhi: ['1'] }],
        }
        return e
      })
  )
  .concat(state4)
const RemoteMetertablejson = [
  { label: '桩号', value: 'gtel' },
  { label: '电量', value: 'dl', fl: '100' },
  { label: '添加时间', value: 'sjc' },
  {
    label: '费用',
    value: 'RemoteMeterje',
    callback: (e) => {
      let r = ((parseInt(e.dl) * parseInt(e.jedbdf)) / 10000).toFixed(2)
      if (isNaN(r)) {
        r = 0
      }
      return r
    },
  },
]

// ["gtel", "dldl", "sjc", "RemoteMeterje"],
export default {
  searchjson: ChargeCarsearchjson,
  tablejson: ChargeCartablejson,
  addjson: ChargeCaraddjson,
  addsjson: addsjson,
  edtjson: ChargeCaredtjson,
  defaultdatavalue: defaultdatavalue,
  exceldata: exceldata,
  ChargeCfglx51: ChargeCfglx51,
  ChargeCfglx65: ChargeCfglx65,
  statesjson: states,
  RemoteMetertablejson: RemoteMetertablejson,
  ChargeCartypejson,
}
